package cn.bluethink.eguan.trader.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Id;
import javax.persistence.Table;

import cn.bluethink.eguan.model.core.EgBag;
import cn.bluethink.eguan.model.core.EgObject;
import cn.bluethink.eguan.model.trader.EgTrader;
import cn.bluethink.eguan.model.trader.EgTraderStatus;

/**
 * 神秘商人实体模型
 * 
 * @author 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.3.0
 * @brief 驿馆+产品
 * @note 修订历史： 1.wanglei于2018/11/26设计并构建初始版本v0.3.0
 */
@Table(name = "eg_trader")
public class EgTraderEntity implements Serializable {

    private static final long serialVersionUID = 4400854177267329666L;

    // 主键
    @Id
    private Long id;

    // 委托人
    private Long actor;

    // 账户
    private Long acount;

    // 商人状态
    private Integer status;

    // 开始时间
    private Date btime;

    // 截止时间
    private Date etime;

    // 包裹ID
    private Long bagid;

    // 所有商品的总价
    private Integer totalbt;

    // 兑换的金币
    private Integer exbt;

    // 创建者
    private Long uid;

    // 商人隶属位置
    private Long fid;

    // 创建时间
    private Date ctime;

    // 更新时间
    private Date utime;

    // 逻辑删除标识
    private Boolean deleteFlag;

    public EgTraderEntity() {

    }

    /**
     * 创建商人实体
     * 
     * @param trader
     * @param acountId
     */
    public EgTraderEntity(EgTrader trader, Long acountId) {
        this.id = trader.getId();
        this.actor = trader.getActor() == null ? null : trader.getActor().getId();
        this.acount = acountId;
        this.status = trader.getStatus() == null ? EgTraderStatus.STATUS_NEW : trader.getStatus();
        this.btime = trader.getBtime();
        this.etime = trader.getEtime();
        this.bagid = trader.getExbag() == null ? null : trader.getExbag().getId();
        this.totalbt = trader.getTotalBt() == null ? 0 : trader.getTotalBt();
        this.exbt = trader.getExbt() == null ? 0 : trader.getExbt();
        this.uid = trader.getCuser() == null ? null : trader.getCuser().getId();
        this.fid = trader.getFid() == null ? 0 : trader.getFid();
        this.ctime = new Date();
        this.utime = ctime;
    }

    /**
     * 更新商人实体
     * 
     * @param trader
     */
    public EgTraderEntity(EgTrader trader) {
        this.id = trader.getId();
        this.actor = trader.getActor() == null ? null : trader.getActor().getId();
        this.status = trader.getStatus() == null ? null : trader.getStatus();
        this.etime = trader.getEtime();
        this.btime = trader.getBtime();
        this.bagid = trader.getExbag() == null ? null : trader.getExbag().getId();
        this.totalbt = trader.getTotalBt() == null ? null : trader.getTotalBt();
        this.exbt = trader.getExbt() == null ? null : trader.getExbt();
        this.utime = new Date();
    }

    /**
     * 转为业务模型
     * 
     * @return
     */
    public EgTrader createEgTrader() {
        EgTrader trader = new EgTrader();
        trader.setId(id);
        if (actor != null && actor > 0) {
            trader.setActor(new EgObject(actor, null, null));
        } else {
            trader.setActor(null);
        }
        trader.setStatus(status);
        trader.setBtime(btime);
        trader.setEtime(etime);
        if (bagid != null && bagid > 0) {
            trader.setExbag(new EgBag(bagid, null));
        } else {
            trader.setExbag(null);
        }
        trader.setTotalBt(totalbt);
        trader.setExbt(exbt);
        if (uid != null && uid > 0) {
            trader.setCuser(new EgObject(uid, null, null));
        } else {
            trader.setCuser(null);
        }
        trader.setUtime(utime);
        trader.setFid(fid);
        return trader;

    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getActor() {
        return actor;
    }

    public void setActor(Long actor) {
        this.actor = actor;
    }

    public Long getAcount() {
        return acount;
    }

    public void setAcount(Long acount) {
        this.acount = acount;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getBtime() {
        return btime;
    }

    public void setBtime(Date btime) {
        this.btime = btime;
    }

    public Date getEtime() {
        return etime;
    }

    public void setEtime(Date etime) {
        this.etime = etime;
    }

    public Long getBagid() {
        return bagid;
    }

    public void setBagid(Long bagid) {
        this.bagid = bagid;
    }

    public Integer getTotalbt() {
        return totalbt;
    }

    public void setTotalbt(Integer totalbt) {
        this.totalbt = totalbt;
    }

    public Integer getExbt() {
        return exbt;
    }

    public void setExbt(Integer exbt) {
        this.exbt = exbt;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public Long getFid() {
        return fid;
    }

    public void setFid(Long fid) {
        this.fid = fid;
    }

    public Date getCtime() {
        return ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }

    public Date getUtime() {
        return utime;
    }

    public void setUtime(Date utime) {
        this.utime = utime;
    }

    public Boolean getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Boolean deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

}
